﻿using System.Linq;
using BenchmarkDotNet.Attributes;
using TiffLibrary.Compression;
using TiffLibrary.Tests.CompressionTests;

namespace TiffLibrary.Benchmarks.Compression
{
    public class CcittGroup3OneDimensionalDecompression
    {
        [Params(0, 1, 2)]
        public int Index { get; set; }

        private TiffDecompressionContext context;
        private byte[] input;
        private byte[] output;

        [GlobalSetup]
        public void Setup()
        {
            var vars = CCITTGroup3OneDimensionalCompressionTests.GetMultiLineTestData().Skip(Index).First();

            int width = (int)vars[0];
            int height = (int)vars[1];
            var photometricInterpretation = (TiffPhotometricInterpretation)vars[2];
            input = (byte[])vars[3];
            output = (byte[])vars[4];

            context = new TiffDecompressionContext
            {
                PhotometricInterpretation = photometricInterpretation,
                BitsPerSample = new TiffValueCollection<ushort>(1),
                ImageSize = new TiffSize(width, height),
                BytesPerScanline = width,
                RequestedScanlines = height
            };
        }


        [Benchmark]
        public void Decompress()
        {
            CcittGroup3OneDimensionalCompressionAlgorithm compression = CcittGroup3OneDimensionalCompressionAlgorithm.GetSharedInstance(TiffFillOrder.HigherOrderBitsFirst);
            compression.Decompress(context, input, output);
        }

    }
}
